<?php

namespace app\link\controller;


use think\facade\App;
use think\facade\Env;
use think\facade\Request;

class Index extends Base {
    
    /**
     * @desc 首页
     */
    public function index() {
        $keyword = input('keyword');
        $logic = App::model('Index', 'logic');
        
        $url = $logic->redirect($keyword);
        $this->redirect($url);
    }
    
    /**
     * @desc 访问错误链接
     * @return \think\response\View
     */
    public function shortError() {
        $tips = input('tips');
        $siteUrl = Env::get('app.site_url');
        $this->assign('tips', $tips);
        $this->assign('siteUrl', $siteUrl);
        return view();
    }
    
    /**
     * @desc 访问私密链接
     * @return \think\response\View
     */
    public function password(){
        $keyword = input('keyword');
        $this->assign('keyword', $keyword);
        return view();
    }
    
    /**
     * @desc 效验密码
     * @return array
     */
    public function checkPassword() {
        $keyword  = Request::post('keyword');
        $password = Request::post('password');
    
        $logic = model('Index', 'logic');
        $data = [];
        try {
            $data = $logic->checkPassword($keyword, $password);
        } catch (\Exception $e) {
            $logic->errorCode = EC_FAILURE;
            $logic->message = $e->getMessage();
        }
        return send_response($data, $logic->errorCode);
    }
}
